package com.ruoyi.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.AuctionComment;
import com.ruoyi.demo.service.IAuctionCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 商品评论Controller
 *
 * @author metaee
 * @date 2025-05-06
 */
@Api(tags = "商品评论管理")
@RestController
@RequestMapping("/demo/comment")
public class AuctionCommentController extends BaseController
{
    @Autowired
    private IAuctionCommentService auctionCommentService;

    /**
     * 查询商品评论列表
     */
    @ApiOperation("查询商品评论列表")
    @PreAuthorize("@ss.hasPermi('demo:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuctionComment auctionComment)
    {
        startPage();
        List<AuctionComment> list = auctionCommentService.selectAuctionCommentList(auctionComment);
        return getDataTable(list);
    }

    /**
     * 导出商品评论列表
     */
    @ApiOperation("导出商品评论列表")
    @PreAuthorize("@ss.hasPermi('demo:comment:export')")
    @Log(title = "商品评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuctionComment auctionComment)
    {
        List<AuctionComment> list = auctionCommentService.selectAuctionCommentList(auctionComment);
        ExcelUtil<AuctionComment> util = new ExcelUtil<AuctionComment>(AuctionComment.class);
        util.exportExcel(response, list, "商品评论数据");
    }

    /**
     * 获取商品评论详细信息
     */
    @ApiOperation("获取商品评论详细信息")
    @PreAuthorize("@ss.hasPermi('demo:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@ApiParam(value = "商品评论ID", required = true) @PathVariable("commentId") Long commentId)
    {
        return success(auctionCommentService.selectAuctionCommentByCommentId(commentId));
    }

    /**
     * 新增商品评论
     */
    @ApiOperation("新增商品评论")
    @PreAuthorize("@ss.hasPermi('demo:comment:add')")
    @Log(title = "商品评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuctionComment auctionComment)
    {
        return toAjax(auctionCommentService.insertAuctionComment(auctionComment));
    }

    /**
     * 修改商品评论
     */
    @ApiOperation("修改商品评论")
    @PreAuthorize("@ss.hasPermi('demo:comment:edit')")
    @Log(title = "商品评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuctionComment auctionComment)
    {
        return toAjax(auctionCommentService.updateAuctionComment(auctionComment));
    }

    /**
     * 删除商品评论
     */
    @ApiOperation("删除商品评论")
    @PreAuthorize("@ss.hasPermi('demo:comment:remove')")
    @Log(title = "商品评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@ApiParam(value = "商品评论ID数组", required = true) @PathVariable Long[] commentIds)
    {
        return toAjax(auctionCommentService.deleteAuctionCommentByCommentIds(commentIds));
    }
}
